<?php

class AdminModule extends CWebModule
{
	public function init()
	{
		$this->setLayoutPath("protected/modules/admin/views/layouts");
		// this method is called when the module is being created
		// you may place code here to customize the module or the application

		// import the module-level models and components
		$this->setImport(array(
			'admin.models.*',
			'admin.components.*',
		));

		Yii::app()->setComponents(array(
            'errorHandler'=>array(
                'errorAction'=>'admin/default/error',
            ),
		));
	}

    public function beforeControllerAction($controller, $action)
    {
        if(parent::beforeControllerAction($controller, $action))
        {
            if (Yii::app()->user->isGuest)
            {
                $loginUrl = Yii::app()->user->loginUrl;
                Yii::app()->user->setFlash('unauth','You are not authenticated to performan such action! Please login');
                Controller::redirect(Controller::createUrl($loginUrl[0]));
            }
            else
            {
                Yii::app()->widgetFactory->widgets['CBreadcrumbs']=array( 'homeLink'=>CHtml::link('Home', array('/admin')));
                $controller->layout = 'column2';
                // this method is called before any module controller action is performed
                // you may place customized code here
            }

            return true;
        }
        else
        {
            return false;
        }
    }

}
